package Ventanas;

import Descriptores.DescriptorCatalogo;
import Descriptores.DescriptorFichero;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Daniel
 */
public class Ventana2 extends javax.swing.JFrame {

    private ArrayList<DescriptorCatalogo> catalogaciones;
    private ArrayList<DescriptorFichero> ficheros;
    private GUIManager manejador;
    private estados estado;
    private String docBase;
    private String id;

    /** Creates new form Ventana2 */
    public Ventana2(GUIManager m) {
        manejador = m;
        catalogaciones = new ArrayList<DescriptorCatalogo>();
        ficheros = new ArrayList<DescriptorFichero>();
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(d.width / 3, 20);
        initComponents();
        this.setTitle("Ventana 2");
        this.setDefaultCloseOperation(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botonSiguiente = new javax.swing.JButton();
        labelTitulo = new javax.swing.JLabel();
        textTitulo = new javax.swing.JTextField();
        labelDescripcion = new javax.swing.JLabel();
        scrollDescripcion = new javax.swing.JScrollPane();
        textDescripcion = new javax.swing.JTextArea();
        panelCat = new javax.swing.JPanel();
        labelDescripcion3 = new javax.swing.JLabel();
        comboTipo = new javax.swing.JComboBox();
        textFuenteCat = new javax.swing.JTextField();
        labelTitulo1 = new javax.swing.JLabel();
        labelTitulo2 = new javax.swing.JLabel();
        textFormatoCat = new javax.swing.JTextField();
        labelTitulo3 = new javax.swing.JLabel();
        textURICat = new javax.swing.JTextField();
        botonAccionCatalogo = new javax.swing.JButton();
        labelDescripcion5 = new javax.swing.JLabel();
        textNombreCat = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaCat = new javax.swing.JTable();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        panelFicheros = new javax.swing.JPanel();
        labelTitulo5 = new javax.swing.JLabel();
        textFormato = new javax.swing.JTextField();
        labelTitulo6 = new javax.swing.JLabel();
        textURIFich = new javax.swing.JTextField();
        botonAddFich = new javax.swing.JButton();
        labelTitulo7 = new javax.swing.JLabel();
        textNomFich = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaFicheros = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        labelDescripcion4 = new javax.swing.JLabel();
        labelDescripcion6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        botonSiguiente.setText("Siguiente");
        botonSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonSiguienteActionPerformed(evt);
            }
        });

        labelTitulo.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo.setText("Titulo:");

        textTitulo.setText("EEUU en el s. XXI");
        textTitulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textTituloActionPerformed(evt);
            }
        });

        labelDescripcion.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelDescripcion.setText("Descripcion:");

        textDescripcion.setColumns(20);
        textDescripcion.setRows(5);
        textDescripcion.setText("Historia moderna de EEUU");
        scrollDescripcion.setViewportView(textDescripcion);

        panelCat.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelDescripcion3.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelDescripcion3.setText("Tipo");

        comboTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "lista_valores", "taxonomia", "tesauro" }));
        comboTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboTipoActionPerformed(evt);
            }
        });

        textFuenteCat.setText("Tahoma");
        textFuenteCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFuenteCatActionPerformed(evt);
            }
        });

        labelTitulo1.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo1.setText("Fuente:");

        labelTitulo2.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo2.setText("Formato:");

        textFormatoCat.setText("pdf");
        textFormatoCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFormatoCatActionPerformed(evt);
            }
        });

        labelTitulo3.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo3.setText("URI:");

        textURICat.setText("/catalogosAmerica/");
        textURICat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textURICatActionPerformed(evt);
            }
        });

        botonAccionCatalogo.setText("Añadir");
        botonAccionCatalogo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAccionCatalogoActionPerformed(evt);
            }
        });

        labelDescripcion5.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelDescripcion5.setText("Nombre:");

        textNombreCat.setText("EEUU_S_XII");
        textNombreCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textNombreCatActionPerformed(evt);
            }
        });

        tablaCat.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Catalogaciones"
            }
        ));
        tablaCat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaCatMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tablaCat);

        jButton5.setText("Desligar");
        jButton5.setActionCommand("Desligar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Eliminar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCatLayout = new javax.swing.GroupLayout(panelCat);
        panelCat.setLayout(panelCatLayout);
        panelCatLayout.setHorizontalGroup(
            panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCatLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCatLayout.createSequentialGroup()
                        .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelCatLayout.createSequentialGroup()
                                .addComponent(labelTitulo2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFormatoCat, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                            .addGroup(panelCatLayout.createSequentialGroup()
                                .addComponent(labelTitulo1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFuenteCat, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                            .addGroup(panelCatLayout.createSequentialGroup()
                                .addComponent(labelDescripcion5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textNombreCat, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                            .addGroup(panelCatLayout.createSequentialGroup()
                                .addComponent(labelDescripcion3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboTipo, 0, 183, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelCatLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6)
                        .addGap(89, 89, 89)
                        .addComponent(botonAccionCatalogo))
                    .addGroup(panelCatLayout.createSequentialGroup()
                        .addComponent(labelTitulo3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textURICat, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelCatLayout.setVerticalGroup(
            panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCatLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelCatLayout.createSequentialGroup()
                        .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelDescripcion5)
                            .addComponent(textNombreCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelDescripcion3)
                            .addComponent(comboTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTitulo1)
                            .addComponent(textFuenteCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTitulo2)
                            .addComponent(textFormatoCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTitulo3)
                    .addComponent(textURICat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(panelCatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAccionCatalogo)
                    .addComponent(jButton5)
                    .addComponent(jButton6)))
        );

        panelFicheros.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelTitulo5.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo5.setText("Formato:");

        textFormato.setText("pdf");
        textFormato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFormatoActionPerformed(evt);
            }
        });

        labelTitulo6.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo6.setText("URI Fichero");

        textURIFich.setText("/docPolitica/");
        textURIFich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textURIFichActionPerformed(evt);
            }
        });

        botonAddFich.setText("Añadir");
        botonAddFich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAddFichActionPerformed(evt);
            }
        });

        labelTitulo7.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo7.setText("Nombre:");

        textNomFich.setText("docusPoliticos");
        textNomFich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textNomFichActionPerformed(evt);
            }
        });

        tablaFicheros.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Ficheros"
            }
        ));
        tablaFicheros.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaFicherosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablaFicheros);

        jButton3.setText("Desligar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Eliminar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelFicherosLayout = new javax.swing.GroupLayout(panelFicheros);
        panelFicheros.setLayout(panelFicherosLayout);
        panelFicherosLayout.setHorizontalGroup(
            panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFicherosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFicherosLayout.createSequentialGroup()
                        .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelFicherosLayout.createSequentialGroup()
                                .addComponent(labelTitulo7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textNomFich, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelFicherosLayout.createSequentialGroup()
                                .addComponent(labelTitulo5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFormato, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE))
                            .addComponent(labelTitulo6, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textURIFich, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFicherosLayout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
                        .addComponent(botonAddFich)))
                .addContainerGap())
        );
        panelFicherosLayout.setVerticalGroup(
            panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFicherosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelFicherosLayout.createSequentialGroup()
                        .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTitulo7)
                            .addComponent(textNomFich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTitulo5)
                            .addComponent(textFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelTitulo6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textURIFich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonAddFich)
                    .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton3)
                        .addComponent(jButton4)))
                .addContainerGap())
        );

        labelDescripcion4.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelDescripcion4.setText("Ficheros:");

        labelDescripcion6.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelDescripcion6.setText("Catalogaciones:");

        jButton1.setText("Cambiar...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cambiar...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton7.setText("Eliminar");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelFicheros, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(scrollDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 190, Short.MAX_VALUE)
                        .addComponent(botonSiguiente))
                    .addComponent(panelCat, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(textTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(labelTitulo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 218, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(labelDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
                        .addComponent(jButton2))
                    .addComponent(labelDescripcion4, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelDescripcion6, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTitulo)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDescripcion)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(labelDescripcion4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelFicheros, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelDescripcion6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonSiguiente)
                    .addComponent(jButton7))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonSiguienteActionPerformed
        if (estado == estados.CREAR) {
            if (camposRellenos()) {
                try {
                    // Insertamos la descripcion en la BBDD
                    manejador.getBBDDManager().creaDescripcion(textTitulo.getText(), textDescripcion.getText());
                    manejador.getBBDDManager().creaDocumento(textTitulo.getText());
                    // Creamos y asociamos sus catalogaciones y ficheros
                    Iterator<DescriptorFichero> itF = ficheros.iterator();
                    while (itF.hasNext()) {
                        // Creamos el fichero en la BBDD
                        DescriptorFichero f = itF.next();
                        manejador.getBBDDManager().creaFicheroDesc(f.getNombre(),
                                f.getFormato(), f.getURI());
                        // Lo relacionamos con el documento
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                                + "descripcionesFichero(descripcion,ficheroDesc) VALUES "
                                + "('" + textTitulo.getText() + "','" + f.getNombre() + "');");
                    }
                    Iterator<DescriptorCatalogo> it = catalogaciones.iterator();
                    while (it.hasNext()) {
                        DescriptorCatalogo cat = it.next();
                        // Creamos la catalogacion en la BBDD
                        manejador.getBBDDManager().creaCatalogacion(cat.getNombre(),
                                cat.getTipo(), cat.getFuente(), cat.getFormato(),
                                cat.getURI());
                        // La relacionamos con el documento
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                                + "catalogacionesDoc(descripcion,catalogacion) VALUES "
                                + "('" + textTitulo.getText() + "','" + cat.getNombre() + "');");
                    }
                    // Borramos listas
                    catalogaciones.clear();
                    actualizaTablaCatalogo();
                    ficheros.clear();
                    actualizaTablaFicheros();
                    manejador.cambiaEstado(estados.VENTANA3);
                } catch (SQLException ex) {
                    System.out.println(ex.toString());
                }
            } else {
                JOptionPane.showMessageDialog(null, "Debes rellnar todos los campos", "Aviso", 2);
            }
        } else if (estado == estados.CONSULTAR) {
            manejador.cambiaEstado(estados.VENTANA1);
        } else if (estado == estados.MODIFICAR){
            //manejador.getV3().mandaEstadoV1(estados.MODIFICAR);
            manejador.cambiaEstado(estados.VENTANA3);
            manejador.setId(id);
        }

    }//GEN-LAST:event_botonSiguienteActionPerformed

    private void textTituloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textTituloActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textTituloActionPerformed

    private void comboTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboTipoActionPerformed

    private void textFuenteCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFuenteCatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textFuenteCatActionPerformed

    private void textFormatoCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFormatoCatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textFormatoCatActionPerformed

    private void textURICatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textURICatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textURICatActionPerformed

    private void botonAccionCatalogoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAccionCatalogoActionPerformed
        if (estado == estado.MODIFICAR) {
            try {
                String consulta;
                consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM catalogacion WHERE `catalogacion`.`nombreCat`='" + textNombreCat.getText() + "';", "nombreCat");
                if (consulta == null) {
                    if (textNomFich.getText().length() > 0 && textFormato.getText().length() > 0 && textURIFich.getText().length() > 0) {
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`catalogacion` (`nombreCat`,`tipo`,`fuente`,`formato`,`uri`) VALUES ('"  + textNombreCat.getText() + "','" + comboTipo.getSelectedItem().toString() + "','" + textFuenteCat.getText() + "','" + textFormatoCat.getText() + "','" + textURICat.getText() + "');");
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`catalogacionesdoc` (`descripcion`,`catalogacion`) VALUES ('" + docBase + "','" + textNombreCat.getText() + "');");
                    } else {
                        JOptionPane.showMessageDialog(null, "Si la catalogacion no existe en la base de datos, se deben rellenar todos los campos.", "Aviso", 2);
                    }
                } else {
                    manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`catalogacionesdoc` (`descripcion`,`catalogacion`) VALUES ('" + docBase + "','" + textNombreCat.getText() + "');");
                }
                cargaTablaCatalogaciones(docBase);
            } catch (SQLException ex) {
                Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {//if (estado == estados.CREAR) {
            if (textNombreCat.getText().length() > 0 && textFormatoCat.getText().length() > 0
                    && textURICat.getText().length() > 0 && textFuenteCat.getText().length() > 0) {
                DescriptorCatalogo catalogo = new DescriptorCatalogo(
                        textNombreCat.getText(),
                        comboTipo.getSelectedItem().toString(), textFuenteCat.getText(),
                        textFormatoCat.getText(), textURICat.getText());
                if (!catalogaciones.contains(catalogo)) {
                    catalogaciones.add(catalogo);
                }
                textNombreCat.setText("");
                textFuenteCat.setText("");
                textFormatoCat.setText("");
                textURICat.setText("");
                actualizaTablaCatalogo();
            } else {
                JOptionPane.showMessageDialog(null, "Debes rellenar todos los campos de la catalogacion", "Aviso", 2);
            }
        }
    }//GEN-LAST:event_botonAccionCatalogoActionPerformed

    private void textNombreCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNombreCatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textNombreCatActionPerformed

    private void textFormatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFormatoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textFormatoActionPerformed

    private void textURIFichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textURIFichActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textURIFichActionPerformed

    private void botonAddFichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAddFichActionPerformed
        if (estado == estado.MODIFICAR) {
            try {
                String consulta;
                consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM fichero_descripcion WHERE `fichero_descripcion`.`nombreFichDoc`='" + textNomFich.getText() + "';", "nombreFichDoc");
                if (consulta == null) {
                    if (textNomFich.getText().length() > 0 && textFormato.getText().length() > 0 && textURIFich.getText().length() > 0) {
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`fichero_descripcion` (`nombreFichDoc`,`formatoFichDoc`,`uriFichDoc`) VALUES ('" + textNomFich.getText() + "','" + textFormato.getText() + "','" + textURIFich.getText() + "');");
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`descripcionesfichero` (`descripcion`,`ficheroDesc`) VALUES ('" + docBase + "','" + textNomFich.getText() + "');");
                    } else {
                        JOptionPane.showMessageDialog(null, "Si el fichero no existe en la base de datos, se deben rellenar todos los campos.", "Aviso", 2);
                    }
                } else {
                    manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`descripcionesfichero` (`descripcion`,`ficheroDesc`) VALUES ('" + docBase + "','" + textNomFich.getText() + "');");
                }
                cargaTablaFicheros(docBase);
            } catch (SQLException ex) {
                Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {//if (estado == estados.CREAR) {

            DescriptorFichero f = new DescriptorFichero(textNomFich.getText(),
                    textFormato.getText(),
                    textURIFich.getText());
            if (textNomFich.getText().length() > 0 && textFormato.getText().length() > 0
                    && textURIFich.getText().length() > 0) {
                if (!ficheros.contains(f)) {
                    ficheros.add(f);
                }
                textNomFich.setText("");
                textFormato.setText("");
                textURIFich.setText("");
                actualizaTablaFicheros();
            } else {
                JOptionPane.showMessageDialog(null, "Debes rellenar todos los campos del fichero", "Aviso", 2);
            }
        }
}//GEN-LAST:event_botonAddFichActionPerformed

    private void textNomFichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNomFichActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textNomFichActionPerformed

private void tablaFicherosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaFicherosMouseClicked
// TODO add your handling code here:
    String fichero = tablaFicheros.getValueAt(tablaFicheros.getSelectedRow(), 0).toString();
    try {
        rellenaDatosFichero(fichero);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_tablaFicherosMouseClicked

private void tablaCatMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaCatMouseClicked
// TODO add your handling code here:
    String catalogacion = tablaCat.getValueAt(tablaCat.getSelectedRow(), 0).toString();
    try {
        rellenaDatosCatalogacion(catalogacion);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_tablaCatMouseClicked

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    try {
        if (textTitulo.getText().length() > 0) {
            manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`descripcion` SET `titulo` = '" + textTitulo.getText() + "' WHERE `descripcion`.`titulo` = '" + docBase + "';");
            docBase = textTitulo.getText();
        } else {
            JOptionPane.showMessageDialog(null, "No puede modificarse si el campo está en blanco.", "Aviso", 2);
            textTitulo.setText(docBase);
        }
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`descripcion` SET `descContenido` = '" + textDescripcion.getText() + "' WHERE `descripcion`.`titulo` = '" + docBase + "';");
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`fichero_descripcion` WHERE `fichero_descripcion`.`nombreFichDoc`='" + textNomFich.getText() + "';");
        cargaTablaFicheros(docBase);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearAcont.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`descripcionesfichero` WHERE `descripcionesfichero`.`descripcion`='" + docBase + "' AND `descripcionesfichero`.`ficheroDesc`='" + textNomFich.getText() + "';");
        cargaTablaFicheros(docBase);
        vaciaDatosFichero();
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearAcont.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`documento` WHERE `documento`.`id`='" + id + "';");
        manejador.cambiaEstado(estados.MODIFICAR);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearAcont.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`catalogacionesdoc` WHERE `catalogacionesdoc`.`descripcion`='" + docBase + "' AND `catalogacionesdoc`.`catalogacion`='" + textNombreCat.getText() + "';");
        cargaTablaCatalogaciones(docBase);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearAcont.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`catalogacion` WHERE `catalogacion`.`nombreCat`='" + textNombreCat.getText() + "';");
        cargaTablaCatalogaciones(docBase);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearAcont.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton6ActionPerformed

    private void actualizaTablaCatalogo() {
        DefaultTableModel m;
        m = new DefaultTableModel(new Object[]{"Catalogaciones"}, 0);
        Iterator<DescriptorCatalogo> it = catalogaciones.iterator();
        while (it.hasNext()) {
            DescriptorCatalogo cat = (DescriptorCatalogo) it.next();
            m.addRow(new Object[]{cat.getNombre()});
        }
        tablaCat.setModel(m);
    }

    private void actualizaTablaFicheros() {
        DefaultTableModel m;
        m = new DefaultTableModel(new Object[]{"Ficheros"}, 0);
        Iterator<DescriptorFichero> it = ficheros.iterator();
        while (it.hasNext()) {
            DescriptorFichero fich = (DescriptorFichero) it.next();
            m.addRow(new Object[]{fich.getNombre()});
        }
        tablaFicheros.setModel(m);
    }

    private boolean camposRellenos() {
        return (textTitulo.getText().length() > 0
                && textDescripcion.getText().length() > 0
                && !catalogaciones.isEmpty()
                && !ficheros.isEmpty());
    }

    void rellena(String doc) {
        try {
            textNombreCat.setText("");
            textFuenteCat.setText("");
            textFormatoCat.setText("");
            textURICat.setText("");
            textNomFich.setText("");
            textFormato.setText("");
            textURIFich.setText("");
            textTitulo.setText(manejador.getBBDDManager().consultaPeticion(
                    "SELECT descripcion FROM documento WHERE descripcion = " + doc + ";", "descripcion"));
            textDescripcion.setText(manejador.getBBDDManager().consultaPeticion(
                    "SELECT descContenido FROM descripcion WHERE titulo=" + doc + ";", "descContenido"));
            DefaultTableModel mFich = (DefaultTableModel) tablaFicheros.getModel();
            String[] fs = manejador.getBBDDManager().consultaPeticion("SELECT ficheroDesc FROM "
                    + "descripcionesFichero WHERE descripcion=" + doc + ";", "ficheroDesc").split(",");
            mFich.addRow(fs);
            DefaultTableModel mCat = (DefaultTableModel) tablaCat.getModel();
            String[] cs = manejador.getBBDDManager().consultaPeticion("SELECT catalogacion FROM "
                    + "catalogacionesDoc WHERE descripcion=" + doc + ";", "catalogacion").split(",");
            mCat.addRow(cs);
        } catch (SQLException ex) {
            System.out.print(ex);
        }
    }

    void mandaEstadoV1(estados s) {
        estado = s;
        if (s == estados.CREAR) {
            botonAddFich.setVisible(true);
            botonAccionCatalogo.setVisible(true);
            botonSiguiente.setText("Siguiente");
            textDescripcion.setEditable(true);
            textFormato.setEditable(true);
            textFormatoCat.setEditable(true);
            textFuenteCat.setEditable(true);
            textNomFich.setEditable(true);
            textNombreCat.setEditable(true);
            textTitulo.setEditable(true);
            textURICat.setEditable(true);
            textURIFich.setEditable(true);
            jButton1.setVisible(false);
            jButton2.setVisible(false);
            jButton3.setVisible(false);
            jButton4.setVisible(false);
            jButton5.setVisible(false);
            jButton6.setVisible(false);
            jButton7.setVisible(false);
        } else if (s == estados.CONSULTAR) {
            botonAddFich.setVisible(false);
            botonAccionCatalogo.setVisible(false);
            botonSiguiente.setText("Volver");
            textDescripcion.setEditable(false);
            textFormato.setEditable(false);
            textFormatoCat.setEditable(false);
            textFuenteCat.setEditable(false);
            textNomFich.setEditable(false);
            textNombreCat.setEditable(false);
            textTitulo.setEditable(false);
            textURICat.setEditable(false);
            textURIFich.setEditable(false);
            jButton1.setVisible(false);
            jButton2.setVisible(false);
            jButton3.setVisible(false);
            jButton4.setVisible(false);
            jButton5.setVisible(false);
            jButton6.setVisible(false);
            jButton7.setVisible(false);
        } else {
            // TODO
            botonSiguiente.setText("Siguiente");
            botonAddFich.setVisible(true);
            botonAccionCatalogo.setVisible(true);
            textDescripcion.setEditable(true);
            textFormato.setEditable(true);
            textFormatoCat.setEditable(true);
            textFuenteCat.setEditable(true);
            textNomFich.setEditable(true);
            textNombreCat.setEditable(true);
            textTitulo.setEditable(true);
            textURICat.setEditable(true);
            textURIFich.setEditable(true);
            jButton1.setVisible(true);
            jButton2.setVisible(true);
            jButton3.setVisible(true);
            jButton4.setVisible(true);
            jButton5.setVisible(true);
            jButton6.setVisible(true);
            jButton7.setVisible(true);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new Ventana2(new GUIManager()).setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(Ventana2.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAccionCatalogo;
    private javax.swing.JButton botonAddFich;
    private javax.swing.JButton botonSiguiente;
    private javax.swing.JComboBox comboTipo;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelDescripcion;
    private javax.swing.JLabel labelDescripcion3;
    private javax.swing.JLabel labelDescripcion4;
    private javax.swing.JLabel labelDescripcion5;
    private javax.swing.JLabel labelDescripcion6;
    private javax.swing.JLabel labelTitulo;
    private javax.swing.JLabel labelTitulo1;
    private javax.swing.JLabel labelTitulo2;
    private javax.swing.JLabel labelTitulo3;
    private javax.swing.JLabel labelTitulo5;
    private javax.swing.JLabel labelTitulo6;
    private javax.swing.JLabel labelTitulo7;
    private javax.swing.JPanel panelCat;
    private javax.swing.JPanel panelFicheros;
    private javax.swing.JScrollPane scrollDescripcion;
    private javax.swing.JTable tablaCat;
    private javax.swing.JTable tablaFicheros;
    private javax.swing.JTextArea textDescripcion;
    private javax.swing.JTextField textFormato;
    private javax.swing.JTextField textFormatoCat;
    private javax.swing.JTextField textFuenteCat;
    private javax.swing.JTextField textNomFich;
    private javax.swing.JTextField textNombreCat;
    private javax.swing.JTextField textTitulo;
    private javax.swing.JTextField textURICat;
    private javax.swing.JTextField textURIFich;
    // End of variables declaration//GEN-END:variables

    public void cargaDocumento(String documento) {
        try {
            docBase = documento;
            id = manejador.getBBDDManager().consultaPeticion("SELECT * FROM documento WHERE `documento`.`descripcion` = '" + documento + "'", "id");
            textTitulo.setText(documento);
            String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM descripcion WHERE `descripcion`.`titulo` = '" + documento + "'", "descContenido");
            textDescripcion.setText(consulta);
            cargaTablaFicheros(documento);
            cargaTablaCatalogaciones(documento);
        } catch (SQLException ex) {
            Logger.getLogger(VentanaCrearAcont.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void cargaTablaFicheros(String documento) throws SQLException {
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM descripcionesfichero WHERE `descripcionesfichero`.`descripcion`='" + documento + "';", "ficheroDesc");
        tablaFicheros.removeAll();
        if (consulta != null) {
            DefaultTableModel m;
            m = new DefaultTableModel(new Object[]{"Ficheros"}, 0);
            String[] fichs = consulta.split(",");
            System.out.println(fichs);

            for (int k = 0; k < fichs.length; k++) {
                m.addRow(new Object[]{fichs[k]});
            }
            tablaFicheros.setModel(m);
        } else {
            DefaultTableModel m = new DefaultTableModel(new Object[]{"Ficheros"}, 0);
            tablaFicheros.setModel(m);
        }
    }

    ;
    
    private void cargaTablaCatalogaciones(String documento) throws SQLException {
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM catalogacionesdoc WHERE `catalogacionesdoc`.`descripcion`='" + documento + "';", "catalogacion");
        tablaCat.removeAll();
        if (consulta != null) {
            DefaultTableModel m;
            m = new DefaultTableModel(new Object[]{"Catalogaciones"}, 0);
            String[] cats = consulta.split(",");
            System.out.println(cats);

            for (int k = 0; k < cats.length; k++) {
                m.addRow(new Object[]{cats[k]});
            }
            tablaCat.setModel(m);
        } else {
            DefaultTableModel m = new DefaultTableModel(new Object[]{"Catalogaciones"}, 0);
            tablaCat.setModel(m);
        }
    }

    ;
    
    private void rellenaDatosFichero(String fichero) throws SQLException {
        textNomFich.setText(fichero);
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`fichero_descripcion` WHERE `fichero_descripcion`.`nombreFichDoc`='" + fichero + "';", "formatoFichDoc");
        textFormato.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`fichero_descripcion` WHERE `fichero_descripcion`.`nombreFichDoc`='" + fichero + "';", "uriFichDoc");
        textURIFich.setText(consulta);
    }

    private void rellenaDatosCatalogacion(String catalogacion) throws SQLException {
        textNombreCat.setText(catalogacion);
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`catalogacion` WHERE `catalogacion`.`nombreCat`='" + catalogacion + "';", "tipo");
        if (consulta.equals("lista_valores")) {
            comboTipo.setSelectedIndex(0);
        } else if (consulta.equals("taxonomia")) {
            comboTipo.setSelectedIndex(1);
        } else if (consulta.equals("tesauro")) {
            comboTipo.setSelectedIndex(2);
        }
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`catalogacion` WHERE `catalogacion`.`nombreCat`='" + catalogacion + "';", "fuente");
        textFuenteCat.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`catalogacion` WHERE `catalogacion`.`nombreCat`='" + catalogacion + "';", "formato");
        textFormatoCat.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`catalogacion` WHERE `catalogacion`.`nombreCat`='" + catalogacion + "';", "uri");
        textURICat.setText(consulta);
    }

    private void vaciaDatosFichero() {
        textNomFich.setText("");
        textFormato.setText("");
        textURIFich.setText("");
    }
}
